package com.thread.n4;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.ReentrantLock;

@Slf4j(topic = "c.TestDeadLock")
public class TestDeadLock {
    public static void main(String[] args) {

        test1();
    }
    private static void test1(){
        Object A=new Object();
        Object B=new Object();
        Thread t1=new Thread(()->{
           synchronized (A){
               log.debug("lockA");
               try {
                   Thread.sleep(1);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
               synchronized (B){
                   log.debug("lock B");
                   log.debug("do ");
               }
           }
        },"t1");

        Thread t2=new Thread(()->{
            synchronized (B){
                log.debug("lock B");
                try {
                    Thread.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (A){
                    log.debug("lock A");
                    log.debug("do ");
                }
            }
        },"t2");
        t1.start();
        t2.start();
    }

}
